/**
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS may be copied only under the terms of the GNU General
* Public License V3, which may be found in the FastDFS source kit.
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/

//queue.h

#ifndef _QUEUE_H
#define _QUEUE_H 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <event.h>
#include <pthread.h>
#include "fnio_define.h"

struct fnio_buff_node
{
	char *data;
	int length; //data length
	int size;
	int offset;
	struct fnio_buff_node *next;
};

struct fnio_buff_chain
{
	struct fnio_buff_node *head;
	struct fnio_buff_node *tail;
};

struct fnio_queue_info
{
	struct fnio_buff_node *head;
	struct fnio_buff_node *tail;
	pthread_mutex_t lock;
};

struct fnio_send_buff {
	char *send_buff;
	char *buff_end;
	char *send_start;
	int send_bytes;
	char *free_start;
	int malloc_size;
	int max_used_bytes;
	int keep_count;
};

#ifdef __cplusplus
extern "C" {
#endif

int fnio_queue_init();
void fnio_queue_destroy();

int free_queue_push(struct fnio_buff_node *pTask);
struct fnio_buff_node *free_queue_pop();
int free_queue_count();

int fnio_malloc_send_buff(struct fnio_send_buff *pSendBuff);
int fnio_push_to_send_buff(struct fnio_send_buff *pSendBuff, \
		const char *data1, const int data_len1, \
		const char *data2, const int data_len2);

#ifdef __cplusplus
}
#endif

#endif

